use url::Url;
use hamcrest as ham;
-use cargo::util::{process,ProcessBuilder};
+use cargo::util::ProcessBuilder;
use cargo::util::ProcessError;
+use cargo::util::process;
use support::paths::CargoPathExt;
}
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
- let mut p = process(program).unwrap();
+ let mut p = process(program);
p.cwd(&self.root())
.env("HOME", &paths::home())
.env_remove("CARGO_HOME") // make sure we don't pick up an outer one
Url::from_file_path(&*p).ok().unwrap()
}
+pub fn cwd() -> PathBuf {
+ env::current_dir().unwrap()
+}
+
pub static RUNNING: &'static str = " Running";
pub static COMPILING: &'static str = " Compiling";
pub static DOCUMENTING: &'static str = " Documenting";
test!(list_commands_looks_at_path {
let proj = project("list-non-overlapping");
let proj = fake_executable(proj, &Path::new("path-test"), "cargo-1");
- let mut pr = process(&cargo_dir().join("cargo")).unwrap();
+ let mut pr = process(&cargo_dir().join("cargo"));
pr.cwd(&proj.root())
.env("HOME", &paths::home());
});
test!(find_closest_biuld_to_build {
- let mut pr = process(&cargo_dir().join("cargo")).unwrap();
+ let mut pr = process(&cargo_dir().join("cargo"));
pr.arg("biuld").cwd(&paths::root()).env("HOME", &paths::home());
assert_that(pr,
// if a subcommand is more than 3 edit distance away, we don't make a suggestion
test!(find_closest_dont_correct_nonsense {
- let mut pr = process(&cargo_dir().join("cargo")).unwrap();
+ let mut pr = process(&cargo_dir().join("cargo"));
pr.arg("asdf").cwd(&paths::root()).env("HOME", &paths::home());
assert_that(pr,
git = false
"#).unwrap();
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("new").arg("foo")
.cwd(&paths::root())
.env("USER", "foo")
});
test!(cargo_help {
- assert_that(process(&cargo_dir().join("cargo")).unwrap(),
+ assert_that(process(&cargo_dir().join("cargo")),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("help"),
+ assert_that(process(&cargo_dir().join("cargo")).arg("help"),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("-h"),
+ assert_that(process(&cargo_dir().join("cargo")).arg("-h"),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("help").arg("build"),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("build").arg("-h"),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("help").arg("-h"),
execs().with_status(0));
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("help").arg("help"),
execs().with_status(0));
});
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
assert_that(p.cargo("bench"),
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
assert_that(p.cargo("bench"),
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
});
assert_that(&p.bin("foo"), existing_file());
assert_that(
- process(&p.bin("foo")).unwrap(),
+ process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
assert_that(&p.bin("foo"), existing_file());
assert_that(
- process(&p.bin("foo")).unwrap(),
+ process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
assert_that(&p.bin("foo"), existing_file());
assert_that(
- process(&p.bin("foo")).unwrap(),
+ process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
assert_that(&p.bin("foo"), existing_file());
assert_that(
- process(&p.bin("foo")).unwrap(),
+ process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
println!("bin");
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout(&format!("0-5-1 @ alpha.1 in {}\n",
p.root().display())));
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
});
"#);
assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0));
- assert_that(process(&p.bin("examples/hello")).unwrap(),
+ assert_that(process(&p.bin("examples/hello")),
execs().with_stdout("Hello, World!\n"));
- assert_that(process(&p.bin("examples/goodbye")).unwrap(),
+ assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
});
"#);
assert_that(p.cargo_process("test"), execs().with_status(0));
- assert_that(process(&p.bin("examples/hello")).unwrap(),
+ assert_that(process(&p.bin("examples/hello")),
execs().with_stdout("Hello, World!\n"));
- assert_that(process(&p.bin("examples/goodbye")).unwrap(),
+ assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
});
"#);
assert_that(p.cargo_process("build"), execs().with_status(0));
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("slow\n"));
});
assert_that(p.cargo_process("build").arg("--release"),
execs().with_status(0));
- assert_that(process(&p.release_bin("foo")).unwrap(),
+ assert_that(process(&p.release_bin("foo")),
execs().with_stdout("fast\n"));
});
"#);
assert_that(p.cargo_process("build"), execs().with_status(0));
- assert_that(process(&p.bin("foo")).unwrap(), execs().with_status(0));
+ assert_that(process(&p.bin("foo")), execs().with_status(0));
});
test!(deletion_causes_failure {
.file("target/Cargo.toml", "bad-toml");
assert_that(p.cargo_process("build"), execs().with_status(0));
- assert_that(process(&p.bin("foo")).unwrap(), execs().with_status(0));
+ assert_that(process(&p.bin("foo")), execs().with_status(0));
});
test!(lib_with_standard_name {
p.cargo_process("build").exec_with_output().unwrap();
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs());
let loc = p.root().join("Cargo.lock");
execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
let d1_path = &p.build_dir().join("debug").join("deps")
.join(format!("d2{}", env::consts::EXE_SUFFIX));
assert_that(d1_path, existing_file());
- assert_that(process(d1_path).unwrap(), execs().with_stdout("d1"));
+ assert_that(process(d1_path), execs().with_stdout("d1"));
assert_that(d2_path, existing_file());
- assert_that(process(d2_path).unwrap(),
+ assert_that(process(d2_path),
execs().with_stdout("d2"));
});
use support::{COMPILING, UPDATING, RUNNING};
use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that,existing_file};
-use cargo;
use cargo::util::process;
fn setup() {
assert_that(&project.bin("foo"), existing_file());
assert_that(
- cargo::util::process(&project.bin("foo")).unwrap(),
+ process(&project.bin("foo")),
execs().with_stdout("hello world\n"));
});
assert_that(&project.bin("foo"), existing_file());
assert_that(
- cargo::util::process(&project.bin("foo")).unwrap(),
+ process(&project.bin("foo")),
execs().with_stdout("hello world\n"));
});
assert_that(&project.bin("foo"), existing_file());
- assert_that(cargo::util::process(&project.bin("foo")).unwrap(),
+ assert_that(process(&project.bin("foo")),
execs().with_stdout("hello world\n"));
assert_that(project.cargo("build"),
assert_that(&p.bin("parent"), existing_file());
- assert_that(cargo::util::process(&p.bin("parent")).unwrap(),
+ assert_that(process(&p.bin("parent")),
execs().with_stdout("hello world\n"));
});
assert_that(&p.bin("parent"), existing_file());
- assert_that(cargo::util::process(&p.bin("parent")).unwrap(),
+ assert_that(process(&p.bin("parent")),
execs().with_stdout("this is dep1 this is dep2\n"));
});
assert_that(p.cargo("build"),
execs().with_status(0));
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("0\n"));
// Touching bar.rs.in should cause the `build` command to run again.
assert_that(p.cargo("build"),
execs().with_status(0));
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("1\n"));
});
use support::{COMPILING, RUNNING};
use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that, existing_file};
-use cargo;
-use cargo::util::{process};
+use cargo::util::process;
fn setup() {
}
assert_that(&p.bin("foo"), existing_file());
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("test passed\n").with_status(0));
println!("cleaning");
assert_that(&p.bin("foo"), existing_file());
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("zoidberg\n"));
});
assert_that(&p.bin("foo"), existing_file());
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("0\n"));
// Touching bar.rs.in should cause the `build` command to run again.
COMPILING, p.url(),
COMPILING, p.url())));
- assert_that(cargo::util::process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("1\n"));
});
execs().with_status(0));
assert_that(&p.target_bin(&target, "foo"), existing_file());
- assert_that(process(&p.target_bin(&target, "foo")).unwrap(),
+ assert_that(process(&p.target_bin(&target, "foo")),
execs().with_status(0));
});
execs().with_status(0));
assert_that(&p.target_bin(&target, "foo"), existing_file());
- assert_that(process(&p.target_bin(&target, "foo")).unwrap(),
+ assert_that(process(&p.target_bin(&target, "foo")),
execs().with_status(0));
});
execs().with_status(0));
assert_that(&foo.target_bin(&target, "foo"), existing_file());
- assert_that(process(&foo.target_bin(&target, "foo")).unwrap(),
+ assert_that(process(&foo.target_bin(&target, "foo")),
execs().with_status(0));
});
execs().with_status(0));
assert_that(&foo.target_bin(&target, "foo"), existing_file());
- assert_that(process(&foo.target_bin(&target, "foo")).unwrap(),
+ assert_that(process(&foo.target_bin(&target, "foo")),
execs().with_status(0));
});
}
fn cargo_process(s: &str) -> ProcessBuilder {
- let mut p = process(&cargo_dir().join("cargo")).unwrap();
+ let mut p = process(&cargo_dir().join("cargo"));
p.arg(s).cwd(&paths::root())
.env("HOME", &paths::home())
.env_remove("CARGO_HOME");
}
fn my_process(s: &str) -> ProcessBuilder {
- let mut p = process(s).unwrap();
+ let mut p = process(s);
p.cwd(&paths::root()).env("HOME", &paths::home());
return p;
}
fn cargo_process(s: &str) -> ProcessBuilder {
- let mut p = process(&cargo_dir().join("cargo")).unwrap();
+ let mut p = process(&cargo_dir().join("cargo"));
p.arg(s).cwd(&paths::root()).env("HOME", &paths::home());
return p;
}
"#)
.file("a/src/lib.rs", "");
p.build();
- let mut cargo = process(&cargo_dir().join("cargo")).unwrap();
+ let mut cargo = process(&cargo_dir().join("cargo"));
cargo.cwd(&root).env("HOME", &paths::home());
assert_that(cargo.clone().arg("build"), execs().with_status(0));
assert_that(cargo.arg("package").arg("-v").arg("--no-verify"),
test!(login_with_no_cargo_dir {
let home = paths::home().join("new-home");
fs::create_dir(&home).unwrap();
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.arg("login").arg("foo").arg("-v")
.cwd(&paths::root())
.env("HOME", &home),
}
fn cargo_process(s: &str) -> ProcessBuilder {
- let mut b = process(&cargo_dir().join("cargo")).unwrap();
+ let mut b = process(&cargo_dir().join("cargo"));
b.arg(s).cwd(&paths::root()).env("HOME", &paths::home());
b
}
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
assert_that(p.cargo("test"),
assert_that(p.cargo_process("build"), execs());
assert_that(&p.bin("foo"), existing_file());
- assert_that(process(&p.bin("foo")).unwrap(),
+ assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
assert_that(p.cargo("test"),
test!(no_term {
// Verify that shell creation is successful when $TERM does not exist.
- assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ assert_that(process(&cargo_dir().join("cargo"))
.env_remove("TERM"),
execs().with_stderr(""));
});
mod test_cargo_version;
mod test_shell;
-thread_local!(static RUSTC: Rustc = Rustc::new("rustc").unwrap());
+thread_local!(static RUSTC: Rustc = Rustc::new("rustc", &support::cwd()).unwrap());
fn rustc_host() -> String {
RUSTC.with(|r| r.host.clone())